noError() active

Anyway to figure out if "noError()" is in effect?  I want to use a noError()/lastError() pair in a library function, but only if the parent function is not already has that pair active.  The problem is that the function's "lastError()" will erase the parent's expectation that errors are still being trapped.

-Louie

void LibraryFunction()
{   bool WasTrappingErrors = noError is active when this function is called
    noError()
    whatever
    ErrMess = lastError()
    deal with ErrMess
    if (WasTrappingErrors) then noError()   // reinstate noError for the benefit of the calling function
}


llandale - Thu May 28 12:37:11 EDT 2015

Re: noError() active
Mathias Mamsch - Thu May 28 15:59:52 EDT 2015

I am sure, that inside the DXL Context or even in the FLAGS_ reference there is some bit to switch - still I think you are overstreching the use of noError / lastError for error handling in DOORS.
I think noError / lastError should be used only for trapping errors in perms, and therefore only be used around exactly one perm. Your own library functions should have their own error handling in place, e.g.

string LibraryFunction () {
      noError(); 
      some_perm();
      string errMsg = lastError(); 
      
      if (!null errMsg) return "An error occurred: " errMsg
      
      return null // no error
}

void parentFunction () {
    noError(); 
    someMorePerms(); 
    lastError(); 
    
    string sErr = LibraryFunction(); 
    if (sErr) {
        // handle error ..
    }
}

If you do not have your error flag in a predictable state it can be a nightmare to predict how your code will work out. Just my thoughts though,

If you want I can also find a hack for you ;-) Regards, Mathias

Re: noError() active
llandale - Thu May 28 16:28:04 EDT 2015

Mathias Mamsch - Thu May 28 15:59:52 EDT 2015

I am sure, that inside the DXL Context or even in the FLAGS_ reference there is some bit to switch - still I think you are overstreching the use of noError / lastError for error handling in DOORS.
I think noError / lastError should be used only for trapping errors in perms, and therefore only be used around exactly one perm. Your own library functions should have their own error handling in place, e.g.

string LibraryFunction () {
      noError(); 
      some_perm();
      string errMsg = lastError(); 
      
      if (!null errMsg) return "An error occurred: " errMsg
      
      return null // no error
}

void parentFunction () {
    noError(); 
    someMorePerms(); 
    lastError(); 
    
    string sErr = LibraryFunction(); 
    if (sErr) {
        // handle error ..
    }
}

If you do not have your error flag in a predictable state it can be a nightmare to predict how your code will work out. Just my thoughts though,

If you want I can also find a hack for you ;-) Regards, Mathias

Turns out we have unreliable network here (at my new company) and I have successfully "overwridden" the native file "write/read/append" commands.  If a command fails I try again in a loop for a couple seconds.   I need to trap errors around the bridged write/read/append commands (in the library now) but am worried the original code may likewise have error trapped around their write/read/append commands, which they THINK are native perms but now are not.

-Louie

Re: noError() active
Mathias Mamsch - Fri May 29 04:15:01 EDT 2015

llandale - Thu May 28 16:28:04 EDT 2015

Turns out we have unreliable network here (at my new company) and I have successfully "overwridden" the native file "write/read/append" commands.  If a command fails I try again in a loop for a couple seconds.   I need to trap errors around the bridged write/read/append commands (in the library now) but am worried the original code may likewise have error trapped around their write/read/append commands, which they THINK are native perms but now are not.

-Louie

Hmm ... thought it might have to do something with "hooking" existing perms ... I noticed that the noError() state is not passed in an out of eval_. So could it be a possiblilty to wrap the call to your perms inside an eval, where you safely call noError(); ... lastError(); ?

Regards, Mathias

Re: noError() active
Wolfgang Uhr - Fri May 29 09:42:57 EDT 2015

Someone in this thread has told me something about function hooking in doors and it works:

 

bool isInNoErrorMode = false;

void noError_() {
    isInNoErrorMode = true;
 noError();
}

string lastError_() {
 isInNoErrorMode = false;
 return (lastError());
}

void noError() {
 noError_();
}

string lastError() {
 return (lastError_())
}


void myErrorFunction(string sSomething) {
 bool hasExternalErrorMode = isInNoErrorMode;
 if (!hasExternalErrorMode) { noError() };
 int iX = 0;
 iX = 1 / iX;
 if (!hasExternalErrorMode) { print "Test 2: " lastError() };
}


noError();
myErrorFunction("123");
print "Test 1: " lastError();

myErrorFunction("123");

 Best regards

Wolfgang

Re: noError() active
Mathias Mamsch - Fri May 29 16:11:40 EDT 2015

Wolfgang Uhr - Fri May 29 09:42:57 EDT 2015

Someone in this thread has told me something about function hooking in doors and it works:

 

bool isInNoErrorMode = false;

void noError_() {
    isInNoErrorMode = true;
 noError();
}

string lastError_() {
 isInNoErrorMode = false;
 return (lastError());
}

void noError() {
 noError_();
}

string lastError() {
 return (lastError_())
}


void myErrorFunction(string sSomething) {
 bool hasExternalErrorMode = isInNoErrorMode;
 if (!hasExternalErrorMode) { noError() };
 int iX = 0;
 iX = 1 / iX;
 if (!hasExternalErrorMode) { print "Test 2: " lastError() };
}


noError();
myErrorFunction("123");
print "Test 1: " lastError();

myErrorFunction("123");

 Best regards

Wolfgang

Smart Wolfgang! Maybe even create a counter for nesting multi noError() / lastError() calls and push the lastError messages

int errorLvl = 0

string errMsgs[100];


void noError_() {
    errMsgs[errorLvl] = lastError();  // push current error message

     errorLvl++   
     noError();
}

string lastError_() {
 if (errorLvl > 0) errorLvl--;

  if (errorLvL == 0) return lastError(); else return errorMsgs[errorLvl]; // restore the error message
}

void noError() {
 noError_();
}

string lastError() {
 return (lastError_())
}

 

Something like this ... Regards, Mathias

Re: noError() active
Wolfgang Uhr - Mon Jun 01 01:36:50 EDT 2015

Mathias Mamsch - Fri May 29 16:11:40 EDT 2015

Smart Wolfgang! Maybe even create a counter for nesting multi noError() / lastError() calls and push the lastError messages

int errorLvl = 0

string errMsgs[100];


void noError_() {
    errMsgs[errorLvl] = lastError();  // push current error message

     errorLvl++   
     noError();
}

string lastError_() {
 if (errorLvl > 0) errorLvl--;

  if (errorLvL == 0) return lastError(); else return errorMsgs[errorLvl]; // restore the error message
}

void noError() {
 noError_();
}

string lastError() {
 return (lastError_())
}

 

Something like this ... Regards, Mathias

Hi Mathias

Sounds that this is a possibility to realize a routine like "try" and "catch", the only thing which is missing is "throw"

Best regards

Wolfgang

 

Re: noError() active
llandale - Mon Jun 01 19:16:03 EDT 2015

Mathias Mamsch - Fri May 29 16:11:40 EDT 2015

Smart Wolfgang! Maybe even create a counter for nesting multi noError() / lastError() calls and push the lastError messages

int errorLvl = 0

string errMsgs[100];


void noError_() {
    errMsgs[errorLvl] = lastError();  // push current error message

     errorLvl++   
     noError();
}

string lastError_() {
 if (errorLvl > 0) errorLvl--;

  if (errorLvL == 0) return lastError(); else return errorMsgs[errorLvl]; // restore the error message
}

void noError() {
 noError_();
}

string lastError() {
 return (lastError_())
}

 

Something like this ... Regards, Mathias

I don't think you want to change the final behavior of noError/lastError, since noError() right after a noError() has no effect, and lastError() resets things back to normal no matter how many noErrors() there were previously.

Now, if you want to write your own fNoError() and fLastError() functions you got something.

push/pop onto a "Skip" stack, but I'm sure you thought of that.

You need to decide if "fLastError" [1] returns the last error since it's previous paired fNoError() or [2] if it just returns the last error since the most recent fLastError was called.  If [1] and an error was detected then that error string needs to be copied down to all existing stack positions.

I actually have an fNoError/fLastError/fSysErr() suite of library functions but have never liked them.  I think your approach is far sounder; at least when combined with my existing ability to dump all captured errors to date; something a script may want to do before it finishes.

-Louie